import Vue from 'vue'
import VueRouter from 'vue-router'
import layout from '../views/layout/index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home/dashboard'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '../views/login/index.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: layout,
    meta: { title: '首页', icon: 'icon-panel', type: "2" },
    children: [
      { path: 'dashboard', name: 'dashboard', component: () => import(/* webpackChunkName: "dashboard" */ '../views/dashboard/index.vue'), meta: { title: '仪表盘' }, },
      { path: 'data', name: 'data', component: () => import(/* webpackChunkName: "data" */ '../views/dashboard/data.vue'), meta: { title: '设备数据' }, },

    ]
  },
  {
    path: '/device',
    name: 'device',
    component: layout,
    meta: { title: '设备', icon: 'icon-luyouqi', type: "2" },
    children: [
      { path: 'wangguan', name: 'wangguan', component: () => import(/* webpackChunkName: "wangguan" */ '../views/dashboard/wangguan.vue'), meta: { title: '网关' }, },
      { path: 'group', name: 'group', component: () => import(/* webpackChunkName: "group" */ '../views/dashboard/group.vue'), meta: { title: '设备群组' }, },
      { path: 'sensorlist', name: 'sensorlist', component: () => import(/* webpackChunkName: "sensorlist" */ '../views/dashboard/sensorlist.vue'), meta: { title: '传感器列表' } },
    ]
  },
  {
    path: '/cost',
    name: 'cost',
    component: layout,
    meta: { title: '计费', icon: 'icon-fyxx', type: "2" },
    children: [
      { path: 'account', name: 'account1', component: () => import(/* webpackChunkName: "account" */ '../views/dashboard/account.vue'), meta: { title: '账户信息' } },
      { path: 'recharge', name: 'recharge', component: () => import(/* webpackChunkName: "recharge" */ '../views/dashboard/recharge.vue'), meta: { title: '充值记录' } },
      { path: 'record', name: 'record', component: () => import(/* webpackChunkName: "record" */ '../views/dashboard/record.vue'), meta: { title: '使用记录' } },
    ]
  },
  {
    path: '/measurement',
    name: 'measure',
    component: layout,
    meta: { title: '测量类型', icon: 'icon-signal', type: "2" },
    children: [
      { path: 'add', name: 'add', component: () => import(/* webpackChunkName: "add" */ '../views/dashboard/addMeasure.vue'), meta: { title: '添加测量类型' } },
      { path: 'list', name: 'list', component: () => import(/* webpackChunkName: "list" */ '../views/dashboard/measureList.vue'), meta: { title: '测量类型列表' } },
    ]
  },
  {
    path: '/security',
    name: 'security',
    component: layout,
    meta: { title: '安全', icon: 'icon-anquan', type: "1" },
    children: [
      { path: 'add', name: 'add1', component: () => import(/* webpackChunkName: "add" */ '../views/dashboard/addSecurity.vue'), meta: { title: '添加密钥' } },
      { path: 'list', name: 'list1', component: () => import(/* webpackChunkName: "list" */ '../views/dashboard/securityList.vue'), meta: { title: '密钥列表' } },
    ]
  },
  {
    path: '/account',
    name: 'account',
    component: layout,
    meta: { title: '账号', icon: 'icon-account', type: "1" },
    children: [
      { path: 'add', name: 'add2', component: () => import(/* webpackChunkName: "add" */ '../views/dashboard/addAccount.vue'), meta: { title: '添加账号' } },
      { path: 'list', name: 'list2', component: () => import(/* webpackChunkName: "list" */ '../views/dashboard/accountList.vue'), meta: { title: '账号列表' } },
    ]
  },

  {
    path: '*',
    name: 'page404',
    component: () => import(/* webpackChunkName: "404" */ '../views/page404/index.vue')
  }

]

const router = new VueRouter({
  routes
})
// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push(location, onResolve, onReject) {
//   if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
//   return originalPush.call(this, location).catch(err => err)
// }
export default router
